package com.android1.amarena2d.test;

import com.android1.amarena2d.actions.interval.RotateBy;
import com.android1.amarena2d.annotations.Incomplete;
import com.android1.amarena2d.nodes.*;
import com.android1.amarena2d.nodes.sprites.SharedSprite;
import com.badlogic.gdx.graphics.Color;

@Incomplete
public class TransformExampleScene extends Scene {

    final EntityGroup entityGroup;
    final SharedSprite marioSprite;
    final SharedSprite luigiSprite;
    final SharedSprite anchorPoint;

    public TransformExampleScene() {

        engine.getRenderer().setClearColor(Color.WHITE);

        //the current scene layer will be notified on touch events
        touch().makeTouchable(this);

        entityGroup = new EntityGroup(100,100);

        marioSprite = new SharedSprite("assets/anim/mario-walk-1.png");
        entityGroup.add(marioSprite);

        //the position will be relative to mario because we add luigi as a child to him.
        luigiSprite = new SharedSprite(engine.getTextureManager().getTexture("assets/anim/luigi-walk-1.png"), 70, 0);

        //luigi is a child of mario.
        entityGroup.add(luigiSprite);
        add(entityGroup);

        //transforming mario will also affect luigi.
        //starting transform anchor will be 100px above mario.
        marioSprite.transform().setTransformAnchor(marioSprite.getX() +100, marioSprite.getY());
        //we scale them a little bit bigger ( yeah, you're right. will also affect luigi )
        marioSprite.transform().setScale(1.5F);

        //this sprite will represent the anchor point
        add(anchorPoint = new SharedSprite("assets/anchor.png", marioSprite.getX() +100, marioSprite.getY()));

        //place the default FPS counter into the screen
        add(new FpsLabel(10, 20,Color.BLACK));


    }

    @Override
    public boolean onTouchUp(float x, float y, int pointer, boolean isHit) {

        //the touch position will be the new anchor point.
        //will be used for scaling and rotation.
        marioSprite.transform().setTransformAnchor(x, y);
        anchorPoint.setXY(x, y);
        marioSprite.action().run(RotateBy.$(2, 360));

        return true;
    }

}